"""import pygame , sys , random

class ball:
    def shua():
        pygame.display.flip()
    def drawingball(x,y):
        pygame.draw.circle(screen,[255,0,0],[x,y],30,0)
    def drawingbu():
        pygame.draw.rect(screen,[255,255,255],[0,0,700,700],0)
    
z=[100,100]
speed=0
pygame.init()
screen=pygame.display.set_mode([640,640])
screen.fill([255,255,255])
ball.shua()
clock = pygame.time.Clock
running=True

while running:
    clock.tick(30)
    for event in pygame.vent.get():
        if event.type==pygame.QUIT:
            running=False
        if event.type==pygame.KEYDOWN:
            if event.key==pygame.K_LEET:
                speed=2
            if event.key==pygame.K_RIGHT:
                speed=1
            else:
                speed=0
        if speed==1:
            z[1]+=10
        if speed==2:
            z[1]-=10
        ball.drawingbu()
        ball.drawingball(z[0],z[1])
        ball.shua()



https://www.ixigua.com/7247522270032167485?logTag=c5fea8452308b1542be2
https://www.ixigua.com/7058853598515593735?logTag=ed2a72e892c19c2e1626
https://www.ixigua.com/7273156650255516195?id=7214452476207399463&logTag=e28c46ddec927bd0291d
遇事不决 量子力学 脑洞不够 平行宇宙
https://www.ixigua.com/7108219207308804615?logTag=c1fae5b960a6b01cd9fd
https://www.ixigua.com/7083431174659375647?logTag=1b3505a3dbb55c37a6d3
https://www.ixigua.com/7175436535859249667?logTag=0ac213b25182d1ca9ddd
https://www.ixigua.com/7250149919368053259?logTag=b120a6cf96a2acbc9c22 
https://www.ixigua.com/6833688310557180429?logTag=ad80cb800e62f3ce8c6b
https://www.ixigua.com/home/97707437397/?source=pgc_author_profile&list_entrance=anyVideo gGM
 https://www.ixigua.com/7061266380607357453?logTag=068f22f1f5f034956d31
https://www.ixigua.com/6951248560872489504?logTag=d09ba4d2eadccfc6bbb9 河图洛书：中国上古时期第一本书籍，高等文明的产物
vhttps://www.ixigua.com/6909209917337371148?logTag=4918068e876273ef9b1f 冰人奥茨，轰动欧洲的考古，终于把历史提至公元前3100年 法国《死亡游戏》，以服从权威为名，人性到底有多残暴
https://www.ixigua.com/6730134559922323976?logTag=656700e6d5e5b407366b π为什么不能被穷尽？与理性思维
https://www.ixigua.com/6915980546170421763?id=6867700546665447950&logTag=d13bef4d9ff6e534a518 我们为什么会爱上别人？科学研究也许都是“命中注定”
https://www.ixigua.com/6909209917337371148?logTag=4918068e876273ef9b1f 蝴蝶效应，逆天改命，这个视频或许会改变你的人生
https://www.ixigua.com/6979608013069877791?logTag=d8d14f0e717be17ec5b4 
https://www.ixigua.com/7263657165431570979?logTag=9ea410bad83b45b6f068 刘慈欣未出版的长篇科幻处女座《中国2185》，太敢写了！
https://www.ixigua.com/7042633778048533000?logTag=0cceca0b2e87a9c462fe 汉语VS英语，哪个才是人类文明的终极选择？
https://www.ixigua.com/6993989856326222373?logTag=6f17bff9ddf8a706dd5d 睡眠真相：抱歉，我们无法补救熬夜【人体简史】第八集
睡眠真相：抱歉，我们无法补救熬夜【人体简史】第八集
https://www.ixigua.com/7048580530350064158?id=7276438780134097467&logTag=4d6e77dd0dda872bb59c科幻：地球毁灭，最后一个男人在月球苟活，只能捡垃圾造飞船
https://www.ixigua.com/7048580530350064158?id=7237834049744699916&logTag=ea30162fa966b78044ab
https://www.ixigua.com/7048580530350064158?id=7163997623744102950&logTag=74cf9769a3d2ac42d401 科幻：未来中国高铁建到太阳系，40天就到火星，春运仍然很震撼
坐在这里坐在这里坐在这里坐在这里坐在这里坐在
random(0,1)
https://haokan.baidu.com/v?vid=9920999529058601707&collection_id=9246366200732538827&
https://haokan.baidu.com/v?vid=15782275433523219417&
https://www.ixigua.com/7287413124981129728?logTag=42d397b62450fdca2ab5
https://www.ixigua.com/7285336560202220068?logTag=77dcdfb27a37e93c93c7
https://www.ixigua.com/6887413767445938699?logTag=35fcb806bf751302c984
https://www.ixigua.com/7065937218086371843?logTag=dc6ea414f4bf5fbb427f
https://www.ixigua.com/7287624035071230518?logTag=8c3691cb5dbcb56612c3
https://www.ixigua.com/7286435495490355746?logTag=71f261c55a269e36794c
https://www.ixigua.com/7288260480563413504?logTag=465a856873f43c6c9623
https://www.ixigua.com/6857823741355753995?id=6888291360953074180&logTag=48bcd173ee39809daa63



https://www.ixigua.com/7281960043279778315?logTag=1dbca406668f5a74083b
https://www.ixigua.com/7264419193142018595?logTag=e62b15a8f36adba17601
https://www.ixigua.com/6930494414624129549?logTag=1d7f53bff698a845a438 
  
https://www.ixigua.com/7123854088802042383?logTag=31bbcbf992ccd235d819
https://www.ixigua.com/7263290199436689955?logTag=dc381ec22fd8b73274a3
https://www.ixigua.com/7291949509200839187?logTag=d0bc38d48e7612f802d3
https://www.ixigua.com/7291949509200839187?logTag=d0bc38d48e7612f802d3
https://www.ixigua.com/7119768625061298703?id=7077478353074127373&logTag=6e98cd058671bd489529

vhttps://www.ixigua.com/6915980546170421763?id=7254451943488422459&logTag=8abaed351c4e67ddf5f1
https://www.ixigua.com/6853485314975990285?logTag=a4803059e93b27d31bca v
v https://www.ixigua.com/7290109556125139517?logTag=d3e35d7d2c47af707c47
https://www.ixigua.com/7190661909832532519?id=7283428177001742884&logTag=8705214a4a3c795fdd17
"""
from pygame import pygame
pygame.init()
screen=pygame.display.set_mode([640,640])
screen.fill((255,255,255))
pygame.draw.circle(screen,[255,0,0],[320,240],30,0)
pygame.display.flip()
running=True
while running:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            running=False
pygame.quit()

"""

import pygame,sys,random,time
pygame.init()

def shua():
    pygame.display.flip()
w=[600,800]
x=[0,30]
y,c=[0,20],[255,0,0]
x2=50

w1(screen,pygame,w,fen)
clock=pygame.time.Clock()
r=True
while r:
    #clock.tick(100)
    #time.sleep(0.001)
    for event in pygame.event.get():
        if  event.type == pygame.MOUSEBUTTONUP:
            if event.button==1:
                x1,y1=event.pos
                if draw(screen,x,y,x1,y1,c):
                    r=False
    screen.fill((255,255,255))
    x2,y2 = pygame.mouse.get_pos()
    drawflip(screen,c,[0,30],[0,20])
    drawlines(pygame,screen)
    #print(x2)
    #print(ball)
    ball=ballzhuang(ball,x2)
    pygame.draw.rect(screen,[0,255,0],[x2-70,780,140,20],0)
    pygame.draw.circle(screen, [255,0,0], [ball[0],ball[1]], 10)

    font = pygame.font.Font(None, 60)
    my_score = font.render("score:", True, c)    #设置分数显示，白色
    screen.blit(my_score, (350, 0))
    score=int(ball[6])
    my_score = font.render(str(score), True, c)    #设置分数显示，白色
    screen.blit(my_score, (500, 0))
    weizhi=ball[5]
    w=350
    while weizhi>0:
        pygame.draw.circle(screen,[255,0,0],[w+10,50],10)
        w+=30
        weizhi-=1

    while ball[4]:
        if ball[5]>0:
            drawflip(screen,c,[200,400],[500,550])
            drawflip(screen,c,x,y)
            drawlines(pygame,screen)
            pygameprint(screen,"play",pygame,60,[255,255,255],[250,500])
            pygame.display.update()
            for event in pygame.event.get():
                if  event.type == pygame.MOUSEBUTTONUP:
                    if event.button==1:
                        x1,y1=event.pos
                        if draw(screen,[200,400],[500,550],x1,y1,c):
                            ball[4]=False
                            ball[1]=random.randint(100,500)
                            ball[0]=random.randint(100,500)
                            pygame.draw.circle(screen, [255,0,0], [ball[0],ball[1]], 10)
                            pygame.display.update()
                            time.sleep(0.5)
                        if draw(screen,x,y,x1,y1,c):
                            hui(f,fen)
                            print(2)
                            pygame.quit()
        if ball[5]<=0:
            screen.fill((255,255,255))
            drawflip(screen,c,x,y)
            drawlines(pygame,screen)
            my_score = font.render("game.over", True, c)    #设置分数显示，白色
            screen.blit(my_score, (200, 450))
            pygame.display.update()
            time.sleep(2)
            fen[0]+=int(ball[6])
            tulifen(fen)
            w1(screen,pygame,[600,800],fen)
            hui(f,fen)
            print(3)
            ball=[random.randint(100,500),random.randint(100,500),4,4,False,3,0,0,0,0]

        drawflip(screen,c,[200,400],[500,550])
        drawflip(screen,c,x,y)
    if ball[9]>=5:
        ball[5]+=1
        ball[9]-=5
        if ball[3]<10 and ball[3]>-10:
            if ball[3]>0:
                ball[3]+=2
            if ball[3]<0:
                ball[3]-=2
            if ball[2]>0:
                ball[2]+=2
            if ball[2]<0:
                ball[2]-=2
    pygame.display.update()           #更新窗口，保证窗口始终打开
    #time.sleep(0.005)  
    clock.tick(50)
#hui(f,fen)
fp.close()
pygame.quit()

"""

"""

import pygame,sys,random,time
pygame.init()

def shua():
    pygame.display.flip()
w=[600,800]
x=[0,30]
y,c=[0,20],[255,0,0]
x2=50

def hui(f,fen):
    s=str(fen[0])
    s1=str(fen[1])
    s2=str(fen[2])
    s3=str(fen[3])
    s4=str(fen[4])
    #s5=str(fen[5])
    f.writelines([s+"\n",s1+"\n",s2+"\n",s3+"\n",s4+"\n"])#,s5+"\n"])
fp="python3/study/pong.game2.txt"
f=open(fp,"r+")
oldfen=int(f.readline(100))
fen1=int(f.readline(100))
fen2=int(f.readline(100))
fen3=int(f.readline(100))
fencha=int(f.readline(100))
min=0
def tulifen(fen):
    oldfen=fen[0]
    fen1=fen[1]
    fen2=fen[2]
    fen3=fen[3]

    fencha=fen[4]
    xx=True
    while xx:
        if oldfen<fen3:
            fen[5]=int((fen3-oldfen)/fencha)
            xx=False
        if oldfen>fen3:
            if oldfen>fen2:
                if oldfen>fen1:
                    fen[5]=1
                    xx=False
                else:
                    fen[5]=2
                    xx=False
            else:
                fen[5]=3
                xx=False
    fen=[oldfen,fen1,fen2,fen3,fencha,min]
fen=[oldfen,fen1,fen2,fen3,fencha,min]
tulifen(fen)
ball=[random.randint(100,500),random.randint(100,500),4,4,False,3,0,0,0,0]
screen=pygame.display.set_mode(w)
screen.fill((255,255,255))
shua()

def ballzhuang(ball,x):
    if ball[0]<=10:
        ball[2]=-(ball[2])
    if ball[0]>=590:
        ball[2]=-(ball[2])
    if ball[1]<=10:
        ball[3]=-(ball[3])
    if ball[1]>770:
        if ball[0]<x-70 or ball[0]>x+70:
            ball[4]=True
            ball[5]-=1
            ball[8]+=1
        elif ball[7]==0:
            ball[3]=-(ball[3])
            ball[6]+=(-(ball[3])/2)*ball[5]
            ball[9]+=1
        ball[7]=7
    if ball[7]>0:
        ball[7]-=1
    ball[0]+=ball[2]
    ball[1]+=ball[3]
    return ball

def drawflip(screen,c,x,y):
    pygame.draw.rect(screen,c,[int(x[0]),int(y[0]),int(x[1]-x[0]),int(y[1]-y[0])],0)
    #shua()

def draw(screen,x,y,x1,y1,c):#x,y,列表。x1,y1,鼠标位置，c,颜色
    drawflip(screen,c,x,y)
    if x1>x[0] and x1<x[1]:
        if y1>y[0] and y1<y[1]:
            return True
        else:
            return False
    else:
        return False

def pygameprint(screen,p,pygame,daxiao,c,weizhi):
    score=str(p)
    font = pygame.font.Font(None, daxiao)
    my_score = font.render(str(score), False, c)    #设置分数显示，白色
    screen.blit(my_score, (weizhi[0], weizhi[1])) 
    shua()

def drawlines(pygame,screen):
    pygame.draw.lines(screen,[255,255,255],True,[[int(x[0]),int(y[0])],[int(x[1]),int(y[1])]],2)
    pygame.draw.lines(screen,[255,255,255],True,[[int(x[1]),int(y[0])],[int(x[0]),int(y[1])]],2)

drawflip(screen,c,x,y)
drawlines(pygame,screen)
shua()

def drawfen(pygame,screen,fen):
    pygame.draw.rect(screen,[155,155,155],[150,600,300,150],0)
    pygame.draw.rect(screen,[55,55,55],[150,600,300,30],1)
    pygame.draw.rect(screen,[55,55,55],[150,630,300,30],1) 
    pygame.draw.rect(screen,[55,55,55],[150,660,300,30],1) 
    pygame.draw.rect(screen,[55,55,55],[150,690,300,30],1)
    pygame.draw.rect(screen,[55,55,55],[150,720,300,30],1)
    x=0
    while x<4:
        font = pygame.font.Font(None, 50)
        if x<3:
            screen.blit(font.render(str(x+1), False, [0,0,0]), (150,600+x*30))
        if x==3:
            screen.blit(font.render(str(fen[5]), False, [0,0,0]), (150,630+x*30))
        x+=1
    #if fen1>min:
    p=[fen[0],fen[1],fen[2],fen[3]]
    p.sort()
    print(p)
    my_score = font.render(str(p[3]), False, [0,0,0])
    screen.blit(my_score, (250,600+0*30))
    my_score = font.render(str(p[2]), False, [0,0,0])
    screen.blit(my_score, (250,630+0*30))
    my_score = font.render(str(p[1]), False, [0,0,0])
    screen.blit(my_score, (250,660+0*30))
    my_score = font.render(str(fen[0]), False, [0,0,0])
    screen.blit(my_score, (250,720+0*30))

    
    shua()
def w1(screen,pygame,w,fen):
    z1=[200,400,500,550]
    c=[255,0,0]
    drawflip(screen,c,[z1[0],z1[1]],[z1[2],z1[3]])
    pygameprint(screen,"play",pygame,60,[255,255,255],[z1[0]+50,z1[2]])
    drawfen(pygame,screen,fen)
    shua()
    r=True
    while r:
        for event in pygame.event.get():
            if  event.type == pygame.MOUSEBUTTONUP:
                if event.button==1:
                    x1,y1=event.pos
                    if draw(screen,x,y,x1,y1,c):
                        r=False
                        hui(f,fen)
                        print(1)
                        pygame.quit()
                    elif draw(screen,[z1[0],z1[1]],[z1[2],z1[3]],x1,y1,c):
                        r=False
                    else:
                        drawflip(screen,c,[z1[0],z1[1]],[z1[2],z1[3]])
                        drawflip(screen,c,x,y)
                        drawlines(pygame,screen)
                        pygameprint(screen,"play",pygame,60,[255,255,255],[z1[0]+50,z1[2]])
        shua()
    pygame.draw.rect(screen,[255,255,255],[0,0,int(w[0]),int(w[1])],0) 
    drawflip(screen,c,x,y)
    drawlines(pygame,screen)
    shua()

w1(screen,pygame,w,fen)
clock=pygame.time.Clock()
r=True
while r:
    #clock.tick(100)
    #time.sleep(0.001)
    for event in pygame.event.get():
        if  event.type == pygame.MOUSEBUTTONUP:
            if event.button==1:
                x1,y1=event.pos
                if draw(screen,x,y,x1,y1,c):
                    r=False
    #pygame.draw.rect(screen,[255,255,255],[0,700,800,100],0)
    #pygame.draw.rect(screen,[255,255,255],[ball[0]-10,ball[1]-10,20,20],0)
    #pygame.draw.rect(screen,[255,255,255],[300,0,200,100])
    screen.fill((255,255,255))
    x2,y2 = pygame.mouse.get_pos()
    drawflip(screen,c,[0,30],[0,20])
    drawlines(pygame,screen)
    #print(x2)
    #print(ball)
    ball=ballzhuang(ball,x2)
    pygame.draw.rect(screen,[0,255,0],[x2-70,780,140,20],0)
    pygame.draw.circle(screen, [255,0,0], [ball[0],ball[1]], 10)

    font = pygame.font.Font(None, 60)
    my_score = font.render("score:", True, c)    #设置分数显示，白色
    screen.blit(my_score, (350, 0))
    score=int(ball[6])
    my_score = font.render(str(score), True, c)    #设置分数显示，白色
    screen.blit(my_score, (500, 0))
    weizhi=ball[5]
    w=350
    while weizhi>0:
        pygame.draw.circle(screen,[255,0,0],[w+10,50],10)
        w+=30
        weizhi-=1

    while ball[4]:
        if ball[5]>0:
            drawflip(screen,c,[200,400],[500,550])
            drawflip(screen,c,x,y)
            drawlines(pygame,screen)
            pygameprint(screen,"play",pygame,60,[255,255,255],[250,500])
            pygame.display.update()
            for event in pygame.event.get():
                if  event.type == pygame.MOUSEBUTTONUP:
                    if event.button==1:
                        x1,y1=event.pos
                        if draw(screen,[200,400],[500,550],x1,y1,c):
                            ball[4]=False
                            ball[1]=random.randint(100,500)
                            ball[0]=random.randint(100,500)
                            pygame.draw.circle(screen, [255,0,0], [ball[0],ball[1]], 10)
                            pygame.display.update()
                            time.sleep(0.5)
                        if draw(screen,x,y,x1,y1,c):
                            hui(f,fen)
                            print(2)
                            pygame.quit()
        if ball[5]<=0:
            screen.fill((255,255,255))
            drawflip(screen,c,x,y)
            drawlines(pygame,screen)
            my_score = font.render("game.over", True, c)    #设置分数显示，白色
            screen.blit(my_score, (200, 450))
            pygame.display.update()
            time.sleep(2)
            fen[0]+=int(ball[6])
            tulifen(fen)
            w1(screen,pygame,[600,800],fen)
            hui(f,fen)
            print(3)
            ball=[random.randint(100,500),random.randint(100,500),4,4,False,3,0,0,0,0]

        drawflip(screen,c,[200,400],[500,550])
        drawflip(screen,c,x,y)
    if ball[9]>=5:
        ball[5]+=1
        ball[9]-=5
        if ball[3]<10 and ball[3]>-10:
            if ball[3]>0:
                ball[3]+=2
            if ball[3]<0:
                ball[3]-=2
            if ball[2]>0:
                ball[2]+=2
            if ball[2]<0:
                ball[2]-=2
    pygame.display.update()           #更新窗口，保证窗口始终打开
    #time.sleep(0.005)  
    clock.tick(50)
#hui(f,fen)
fp.close()
pygame.quit()

"""